﻿using Medical.Api.Read.Application.Command.Wms.WmsStoresCommand;
using Medical.Api.Read.Dto.WmsDto.WmsStoresDro;
using Medical.Api.Read.Service.WmsService;
using Medical.ErrorCode;
using MediatR;
using System.Threading;
using System.Threading.Tasks;

namespace Medical.Api.Read.Application.Handler.Wms.WmsStoresHandler
{
    /// <summary>
    /// 存放列表查询处理器，根据查询参数获取指定货架的存放信息
    /// </summary>
    public class GetStoresListHandler : IRequestHandler<GetStoresListCommand, ApiResult<List<WmsStoresPageDto>>>
    {
        /// <summary>
        /// WMS服务
        /// </summary>
        private readonly IWmsService _wmsService;
        /// <summary>
        /// 构造函数，注入WMS服务
        /// </summary>
        public GetStoresListHandler(IWmsService wmsService)
        {
            _wmsService = wmsService;
        }
        /// <summary>
        /// 查询指定货架的存放信息列表
        /// </summary>
        /// <param name="request">存放列表查询命令</param>
        /// <param name="cancellationToken"></param>
        /// <returns>存放信息列表</returns>
        public async Task<ApiResult<List<WmsStoresPageDto>>> Handle(GetStoresListCommand request, CancellationToken cancellationToken)
        {
            return await _wmsService.GetStoresListAsync(request.QueryDto);
        }
    }
}
